﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace TLSharp
{
    public class Game
    {
        public int GameID;
        public int GameType;
        public DateTime GameDate;
        public DateTime GameTime;
        public bool bStarted = false;
        public bool bComplete = false;
        public bool HasAd = false;
        public string AdType = "";
        public string AdURL = "";
        public string AdTitle = "";
        public string AdText = "";
        public string AdWebTag = "";
        
        public DateTime DateComplete;

        public List<string> GameTeams;
        private List<GameTeam> _GameTeamObjects = null;

        


        public GameTeam Challenger
        {
            get
            {
                foreach (GameTeam ThisTeam in GameTeamObjects)
                {
                    if (ThisTeam.GameTeamTypeID == 1) { return ThisTeam; }
                }
                return null;
            }
        }

        public GameTeam Challengee
        {
            get
            {
                foreach (GameTeam ThisTeam in GameTeamObjects)
                {
                    if (ThisTeam.GameTeamTypeID == 2) { return ThisTeam; }
                }
                return null;
            }
        }

        public List<GameTeam> GameTeamObjects
        {
            get
            {
                if (_GameTeamObjects == null && (GameTeams != null && GameTeams.Count == 2))
                {
                    _GameTeamObjects = new List<GameTeam>();
                    foreach (string ThisString in GameTeams)
                    {
                        Newtonsoft.Json.Linq.JObject o = JObject.Parse(ThisString);

                        GameTeam b = (GameTeam)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(GameTeam));

                        JValue ThisValue = new JValue(ThisString);
                        _GameTeamObjects.Add(b);
                    }
                }
                return _GameTeamObjects;
            }
        }

        


    }
}
